<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="110px">
      <el-form-item label="用户名:">
        <el-input v-model="queryParams.userId" placeholder="请输入用户ID" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="店铺名称:">
        <el-input v-model="queryParams.shopName" placeholder="请输入店铺名称" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="店铺状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="店铺状态" clearable size="small" style="width: 240px">
          <el-option v-for="item in statusOptions" :key="item.value" :label="item.label" :value="item.value" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="shopList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="店铺ID" align="center" prop="shopId" />
      <el-table-column label="店铺名" align="center" prop="shopName" />
      <el-table-column label="用户ID" align="center" prop="userId" />
      <el-table-column label="联系方式" align="center">
        <template slot-scope="scope">
          <span style="
              float: center;
              vertical-align: right;
              display: inline-block;
              line-height: 30px;
            ">
            手机号:{{ scope.row.phone }}
          </span>
          <span style="
              float: center;
              vertical-align: right;
              display: inline-block;
              line-height: 30px;
            ">
            微信号:{{ scope.row.wechat }}
          </span>
        </template>
      </el-table-column>
      <el-table-column label="店铺状态" align="center" prop="shopStatus">
        <template slot-scope="scope">
          <span v-if="scope.row.status === -1">审核拒绝</span>
          <span v-if="scope.row.status === 0">待审核</span>
          <span v-if="scope.row.status === 1">审核通过</span>
        </template>
      </el-table-column>
      <el-table-column label="申请时间" align="center" prop="createTime" />
      <el-table-column label="审核时间" align="center" prop="auditTime" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button v-if="scope.row.status === 0" size="mini" type="text" icon="el-icon-check"
            @click="audit(scope.row)">审核
          </el-button>
          <el-button size="mini" type="text" icon="el-icon-view" @click="handleView(scope.row)">详情
          </el-button>
        </template>
      </el-table-column>

      <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body @close="cancel">
        <el-form ref="form" :model="form" label-width="80px">
          <el-form-item label="审核状态">
            <el-radio-group v-model="resource">
              <el-radio label="1">审核通过</el-radio>
              <el-radio label="-1">审核拒绝</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="submit">确认</el-button>
            <el-button @click="cancel">取消</el-button>
          </el-form-item>
        </el-form>
      </el-dialog>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <el-dialog title="操作日志详细" :visible.sync="detailFormDisable" width="1500px" append-to-body>
      <el-form ref="detailForm" :model="detailForm" label-width="120px" size="mini">
        <el-row>
          <el-col :span="8">
            <el-form-item label="店铺ID：">{{
              detailForm.shopId
            }}</el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="店铺名：">{{
              detailForm.shopName
            }}</el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="店铺状态：">{{
              detailForm.status
            }}</el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="店铺分类：">{{
              detailForm.categoryName
            }}</el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="店铺地址：">{{
              detailForm.address
            }}</el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="店铺简介：">{{
              detailForm.introduction
            }}</el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="用户ID：">{{
              detailForm.userId
            }}</el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="微信：">{{ detailForm.wechat }}</el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="电话：">{{ detailForm.phone }}</el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="身份证正面: ">
              <el-image :src="requestUrl + detailForm.certPhotoA" style="width: 306px; height: 228px"
                :preview-src-list="frontImgList" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="身份证反面: ">
              <el-image :src="requestUrl + detailForm.certPhotoB" style="width: 306px; height: 228px"
                :preview-src-list="reverseImgList" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="营业执照: ">
              <el-image :src="requestUrl + detailForm.licensePhoto" style="width: 306px; height: 228px"
                :preview-src-list="licenseImgList" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="申请时间：">{{
              detailForm.createTime
            }}</el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="审核时间：">{{
              detailForm.createTime
            }}</el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="detailFormDisable = false">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { getShopInfoList, auditShopInfo } from "@/api/admin/shopInfo";

export default {
  name: "Video",
  data () {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 店铺详情管理表格数据
      shopList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      resource: "1",
      form: {},
      statusOptions: [
        {
          value: "0",
          label: "待审核",
        },
        {
          value: "1",
          label: "审核通过",
        },
        {
          value: "-1",
          label: "审核拒绝",
        },
      ],
      requestUrl: this.$img.requestUrl,
      detailFormDisable: false,
      detailForm: {},
      frontImgList: [],
      reverseImgList: [],
      licenseImgList: [],
    };
  },
  created () {
    this.getList();
  },
  methods: {
    /** 查询店铺详情列表 */
    async getList () {
      this.loading = true;
      getShopInfoList(this.queryParams).then((response) => {
        this.shopList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    //审核店铺
    submit () {
      this.form.status = this.resource;
      auditShopInfo(this.form).then((response) => {
        if (response.code === 200) {
          this.msgSuccess("审核成功!");
          this.getList();
          this.reset();
          this.open = false;
        }
      });
    },
    audit (row) {
      this.open = true;
      this.form.shopId = row.shopId;
    },
    /** 搜索按钮操作 */
    handleQuery () {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery () {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange (selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    // 表单重置
    reset () {
      this.form = {};
      this.resetForm("form");
    },
    // 取消按钮
    cancel () {
      this.reset();
      this.open = false;
    },
    handleView (row) {
      this.detailForm = {};
      this.frontImgList = [],
        this.reverseImgList = [],
        this.licenseImgList = [],
        this.detailForm = { ...row };
      this.detailFormDisable = true;
      this.frontImgList.push(this.requestUrl + row.certPhotoA);
      this.reverseImgList.push(this.requestUrl + row.certPhotoB);
      this.licenseImgList.push(this.requestUrl + row.licensePhoto);
    },
  },
};
</script>
